/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-03-07 20:06:15
 * @LastEditors: kl2018
 * @LastEditTime: 2020-07-08 10:14:50
 */
import React from 'react';
import loadjs from 'loadjs';
import Loading from './Loading';

export default class Forward extends React.Component {
  constructor() {
    super();
    this.state = { hasLoad: false };
  }
  componentDidMount() {
    const init = () => {
      const { WFForwardStore } = window.weaWorkflowPublic;
      const store = new WFForwardStore();
      this.setState({ hasLoad: true, store });
    };
    const workflowPublicFiles = [
      '/spa/workflow/static4public/index.js',
      '/spa/workflow/static4public/index.css',
    ];

    loadjs.isDefined('workflowPublic') ? loadjs.ready('workflowPublic', init) : loadjs(workflowPublicFiles, 'workflowPublic', init);
  }
  render() {
    const { hasLoad, store } = this.state;

    if (hasLoad) {
      const { forwardParams = {}, callBackActions = {} } = this.props;

      const { WfForward } = window.weaWorkflowPublic;
      store.setShowForward(forwardParams, callBackActions);
      return (<WfForward ecId={`${this && this.props && this.props.ecId || ''}_WfForward@ndveeg`} wfForwardStore={store} inOdoc />);
    }
      return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@lri6r5`} />);
  }
}
